class @MyMessageListingView extends ScrollPagingView

    initialize:->
        super
        @setElement("#main")
        @model.bind("change",@render)
        @model.fetch()
        $.connection.hub.start()
        @chat = $.connection.chat;
        @chat.client.send=(userId)=>
            if userId==@model.get("UserId")
                @model.set("Page",1)
                @model.fetch()
        return 
    render:->
        @GetTemplate(SiteMap.Messages.MessageListingEmptyTemplate,(template)=>
            $(@el).html(template(@model.toJSON()))
            @startLoading()
            @renewScrolling()
        )

    events:
        "click button.Back":"Back"
        "click button.AddMessage":"AddMessage"

    Back:->
        @Navigate(SiteMap.Messages.UserListing)

    AddMessage:->
        data = $(@el).find("form.general").serialize()
        @model.set("Page",1)
        $.ajax(
            type:"POST"
            url:SiteMap.Messages.AddMessage + "?recepientId="+@model.get("SenderId")
            data:data
            success:(response)=>
                @model.fetch()
                
                $.connection.hub.start().done(()=>
                    @chat.server.send(@model.get("SenderId"))
                )
                return
        )

    afterLoad: (data) =>
        @GetTemplate(SiteMap.Messages.MessageListingTemplate, (compiledTemplate)=>
            $(@el).find("div.message-listing ul").append(compiledTemplate(data))
            return
        )
        return